using UnityEngine;

namespace Exploder.Demo
{
	public class PanelThrowObject : UseObject
	{
		public GameObject ThrowBox;

		public GameObject[] ThrowObjects;

		private void Start()
		{
		}

		public override void Use()
		{
			base.Use();
			GameObject original = ThrowObjects[Random.Range(0, ThrowObjects.Length)];
			GameObject gameObject = Object.Instantiate(original, ThrowBox.transform.position + Vector3.up * 2f, Quaternion.identity) as GameObject;
			gameObject.AddComponent<ThrowObject>();
			gameObject.tag = "Exploder";
			if (gameObject.GetComponent<Rigidbody>() == null)
			{
				gameObject.AddComponent<Rigidbody>();
			}
			if (gameObject.GetComponentsInChildren<BoxCollider>().Length == 0)
			{
				gameObject.AddComponent<BoxCollider>();
			}
			Vector3 up = Vector3.up;
			up.x = Random.Range(-0.2f, 0.2f);
			up.y = Random.Range(1f, 0.8f);
			up.z = Random.Range(-0.2f, 0.2f);
			up.Normalize();
			gameObject.GetComponent<Rigidbody>().velocity = up * 20f;
			gameObject.GetComponent<Rigidbody>().angularVelocity = Random.insideUnitSphere * 3f;
			gameObject.GetComponent<Rigidbody>().mass = 20f;
		}
	}
}
